<!--  -->
<template>
    <div>
        <Card>
            <p slot="title">
                <Icon class="rotate-title-icon" style="color:#2F65EB" type="minus"></Icon>
                维修配置
                <Poptip placement="right-start" trigger="hover"  content="配置“设备维修”流程中的环节和参数。">
                    <Icon  style="color:#2d8cf0;cursor:pointer" type="information-circled"></Icon>
                </Poptip>
            </p>
            <Row type="flex" align="middle" :gutter="10">
                <Col :span="12">
                    允许现场处理距离<InputNumber style="margin:0 5px 0 10px;" :max="2000" :min="500" v-model="configForm.process_distance"></InputNumber>米
                </Col>
            </Row>
            <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                <Col :span="12">
                    分配时间限制<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" v-model="configForm.time_max_distribute"></InputNumber>分钟
                </Col>
                </Row>
                <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                <Col :span="12">
                    接单时间限制<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" v-model="configForm.time_max_take_order"></InputNumber>分钟
                </Col>
            </Row>
            <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                <Col :span="12">
                    处理时间限制<InputNumber style="margin:0 5px 0 10px;" :max="10" :min="1" v-model="configForm.time_max_process"></InputNumber>天
                </Col>
            </Row>
            <Row type="flex" align="middle" :gutter="10" style="marginTop:10px;">
                <Col :span="12">
                    <Button  @click="save" v-if="btnp.xtgl_wxpzhi_bc"  class="zh-hollow" type="primary" >保存</Button>
                </Col>
            </Row>
      </Card>
    </div>
</template>

<script>
import {getRCfg,saveRCfg} from '@/libs/system.js'
import util from '@/libs/util.js'
export default {
name:'',
  data () {
    return {
        btnp:{},
        btn:{
            xtgl_wxpzhi_bc:false
        },
        configForm:{
            uuid:'',
            process_distance:1000,
            time_max_distribute:3,
            time_max_take_order:3,
            time_max_process:5
        }
    };
  },
  methods:{
        async getData(){
            let res= await getRCfg();
            let response=res.data;
            if(response.code==200){
                let data=response.data;
                this.configForm={
                    uuid:data.uuid,
                    process_distance:!!data.process_distance?Number.parseInt(data.process_distance):1000,
                    time_max_distribute:!!data.time_max_distribute?Number.parseInt(data.time_max_distribute):3,
                    time_max_take_order:!!data.time_max_take_order?Number.parseInt(data.time_max_take_order):3,
                    time_max_process:!!data.time_max_process?Number.parseInt(data.time_max_process):5
                }
            }else{
                this.$Notice.error({
                    desc:response.msg
                })
            }
        },
        async save(){
            if(!this.configForm.process_distance){
                this.$Notice.error({
                    desc:'请输入允许现场处理距离'
                })
            }else if(!Number.isInteger(this.configForm.process_distance)){
                this.$Notice.error({
                    desc:'只能输入500~2000范围内的整数'
                })
            }else if(!this.configForm.time_max_distribute){
                this.$Notice.error({
                    desc:'请输入分配时间限制'
                })
            }else if(!Number.isInteger(this.configForm.time_max_distribute)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else if(!this.configForm.time_max_take_order){
                this.$Notice.error({
                    desc:'请输入接单时间限制'
                })
            }else if(!Number.isInteger(this.configForm.time_max_take_order)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else if(!this.configForm.time_max_process){
                this.$Notice.error({
                    desc:'请输入处理时间限制'
                })
            }else if(!Number.isInteger(this.configForm.time_max_process)){
                this.$Notice.error({
                    desc:'只能输入1~10范围内的整数'
                })
            }else{
                let form =JSON.parse(JSON.stringify(this.configForm));
                let res= await saveRCfg(form);
                let response=res.data;
                if(response.code==200){
                    this.$Notice.success({
                        desc:"已保存"
                    })
                }else{
                    this.$Notice.error({
                        desc:response.msg
                    })
                }
            }
        }
  },
  created(){
      this.getData();
      this.btnp=util.bpower(this,this.btn);
  }
}

</script>
<style lang='scss' >
</style>